package pdd;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;

public class Main2_2 {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        int T = Integer.parseInt(s);
        ArrayList<String> list = new ArrayList<>();
        while ((s = br.readLine()) != null) {
            list.add(s);
        }
        for (String s1 : list) {
            String[] s2 = s1.split(" ");
            System.out.println(fun(Integer.parseInt(s2[0]), Integer.parseInt(s2[1])));
        }
    }

    private static int fun(int src, int target) {
        if(src == target) return 0;
        LinkedList<Integer> queue = new LinkedList<>();
        queue.addLast(src);
        int count = 0;
        while (!queue.isEmpty()) {
            int n = queue.size();
            for (int i = 0; i < n; i++) {
                Integer tmp = queue.removeFirst();
                if (tmp == target) return count;
                queue.addLast(tmp - 2);
                queue.addLast(tmp - 1);
                queue.addLast(tmp + 1);
                queue.addLast(tmp * 2);
            }
            count++;
        }
        return 0;
    }

}
